package com.chengccn.tkmybatis.mytest.controller;

import com.chengccn.tkmybatis.mytest.entity.SysUser;
import com.chengccn.tkmybatis.mytest.mapper.SysUserMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import tk.mybatis.mapper.entity.Example;

/**
 * @Author: Administrator
 * @Description:
 * @Date: 2019/5/16 16:39
 * @Version: 1.0
 */
@RestController
public class TkMybatisTestController {

    @Autowired
    private SysUserMapper sysUserMapper;

    /**
     * 测试查询所有数据
     *
     * @return 所有数据
     */
    @GetMapping("/")
    public Object say() {
        return sysUserMapper.selectAll();
    }

    /**
     * 查询分页数据
     *
     * @param page 页数
     * @param size 条数
     * @return pageInfo
     */
    @GetMapping("page/{page}/{size}")
    public Object getPage(@PathVariable("page") int page, @PathVariable("size") int size) {
        PageHelper.startPage(page, size);
        Example example = new Example(SysUser.class);
        PageInfo<SysUser> pageInfo = new PageInfo<SysUser>(sysUserMapper.selectByExample(example));
        return pageInfo;
    }
}
